// console.log($('input[name="uesrname"]').val());
// 用户名


// 点击事件
$('.buttons').on('click',function(){
    nonNull()
    
})

// =======非空验证========
function nonNull(){
    let user =  $('input[name="uesrname"]').val()    
   let passWord = $('input[name="password"]').val()

   if(user == ''){
       alert('用户名不能为空!') 
   }else if(passWord == ''){
    alert('密码不能为空!')
   }else{
       alert('注册成功')
       storage()
       location.href = './Loginpage.html'
   }
  
}
//=======非空验证========



//========= 正则验证===========
function verification(){
    $('input[name="uesrname"]').blur(function(){
        let userName = $('input[name="uesrname"]').val()
        let reg=/^[a-zA-Z][a-zA-Z0-9]{6,10}$/;
        if(!(reg.test(userName))){
        $('.cuowutishi1').html('6-16字符，可以包含字母或数字').css('color','red')
        $('input[name="uesrname"]').val('')  
        }else{
                $('.cuowutishi1').html('输入正确').css('color','green')
            }
        
        })
        
        // 密码正则
        $('input[name="password"]').blur(function(){
            let passWord = $('input[name="password"]').val()
            let reg=/^[a-zA-Z][a-zA-Z0-9]{6,10}$/;
            if(!(reg.test(passWord))){
            $('.cuowutishi2').html('6-16字符，可以包含字母或数字').css('color','red')   
            $('input[name="password"]').val('')        
        }else{
          $('.cuowutishi2').html('输入正确').css('color','green')
             }
            
            })
}
verification()//用户名正则验证
//========= 正则验证结束===========

// =============存取数据================
function 

storage(){
    // let userstr = localStorage.getItem('USERS')
    // let userList = JSON.parse(userstr) || [];  
    
    
    let user =  $('input[name="uesrname"]').val()
    let password = $('input[name="password"]').val()
    

//    console.log(userList);
    let newUser = [
        {user:user,
        password:password,
    }
        
     
]
      

     
localStorage.setItem('USERS', JSON.stringify(newUser))

}
